﻿namespace EggOfPanKu.DeckBuilder.Controls
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;

    using EggOfPanKu.Library.Objects;
    using EggOfPanKu.Library.Infrastructure;

    /// <summary>
    /// Interaction logic for PreviewWindow.xaml
    /// </summary>
    public partial class PreviewWindow : Window
    {
        #region Fields

        private Card _card;

        #endregion Fields

        #region Constructors

        public PreviewWindow()
        {
            InitializeComponent();
        }

        #endregion Constructors

        #region Properties

        public Card Card
        {
            get { return _card; }
            set { _card = value; }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Loads the specified card's Image and information into the PreviewWindow controls
        /// </summary>
        /// <param name="card">Card to load into the PreviewWindow</param>
        /// <param name="imageRoot"></param>
        public void LoadCard(Card card, string imageRoot)
        {
            Card = card;
            PreviewImage.Source = ImageManager.GenerateImageSource(Card.ImagePath);

            if (Card != null)
            {

                TxtName.Text = Card.Name;
                StringBuilder keywordString = new StringBuilder("");
                if (Card.Keywords.Count > 0)
                {
                    for (int i = 0; i < Card.Keywords.Count; i++)
                    {
                        keywordString.Append(Card.Keywords[i]);
                    }
                }
                PreviewText.NavigateToString("<div style=\"text-align:center;font-size:12\">" + keywordString.ToString() + "<br/>" + Card.Text + "</div>");
                switch (Card.CardType.ToString())
                {
                    case "Follower":
                        TxtChi.Text = ((Follower)Card).Chi;
                        TxtCost.Text = ((Follower)Card).Cost;
                        TxtFocus.Text = ((Follower)Card).Focus;
                        TxtForce.Text = ((Follower)Card).Force;
                        TxtHonorReq.Text = ((Follower)Card).HonorRequirement;
                        TxtPersonalHonor.Text = ((Follower)Card).PersonalHonor;
                        break;
                    case "Holding":
                        TxtCost.Text = ((Holding)Card).Cost;
                        break;
                    case "Item":
                        TxtChi.Text = ((Item)Card).Chi;
                        TxtCost.Text = ((Item)Card).Cost;
                        TxtFocus.Text = ((Item)Card).Focus;
                        TxtForce.Text = ((Item)Card).Force;
                        break;
                    case "Personality":
                        TxtChi.Text = ((Personality)Card).Chi;
                        TxtCost.Text = ((Personality)Card).Cost;
                        TxtForce.Text = ((Personality)Card).Force;
                        TxtHonorReq.Text = ((Personality)Card).HonorRequirement;
                        TxtPersonalHonor.Text = ((Personality)Card).PersonalHonor;
                        break;
                    case "Ring":
                        TxtCost.Text = ((Ring)Card).Cost;
                        TxtFocus.Text = ((Ring)Card).Focus;
                        break;
                    case "Spell":
                        TxtCost.Text = ((Spell)Card).Cost;
                        TxtFocus.Text = ((Spell)Card).Focus;
                        break;
                    case "Strategy":
                        TxtCost.Text = ((EggOfPanKu.Library.Objects.Strategy)Card).Cost;
                        TxtFocus.Text = ((EggOfPanKu.Library.Objects.Strategy)Card).Focus;
                        break;
                    default:
                        break;
                }
            }
        }

        #endregion Methods
    }
}